package com.example.jiemian.UI;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.jiemian.R;
import com.example.jiemian.bean.Luntan;
import com.example.jiemian.sqlite.LuntanDBUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class YueduigzActivity extends AppCompatActivity {
    @BindView(R.id.listdatas)
    ListView swipeRefresh;

     Luntan1Adapter luntanAdapter;
    List<Luntan> luntanList;
    @BindView(R.id.rl_back)
    RelativeLayout rlBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right)
    ImageView tvRight;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yueduigz);
        ButterKnife.bind(this);
        tvTitle.setText("关注的乐队");
        tvRight.setVisibility(View.GONE);

        luntanList=new ArrayList<>();
        rlBack.setVisibility(View.GONE);
        luntanAdapter = new  Luntan1Adapter(YueduigzActivity.this, LuntanDBUtils.getInstance(YueduigzActivity.this).findAllByTime("乐队","2"));
        luntanAdapter.notifyDataSetChanged();
        swipeRefresh.setAdapter(luntanAdapter);
    }


    class Luntan1Adapter extends BaseAdapter {
        private List<Luntan> listdata;
        private Context context;

        public Luntan1Adapter(Context context, List<Luntan> listdata) {
            this.context = context;
            this.listdata = listdata;
        }

        @Override
        public int getCount() {
            return listdata.size();
        }

        @Override
        public Object getItem(int position) {
            return listdata.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
             ViewHolder viewHolder = null;
            if (convertView == null) {
                viewHolder = new  ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.item_home_luntan, null);
                viewHolder.iv_pic = convertView.findViewById(R.id.iv_pic);
                viewHolder.image_head = convertView.findViewById(R.id.image_head);
                viewHolder.tv_name = convertView.findViewById(R.id.tv_name);
                viewHolder.tv_biaoti = convertView.findViewById(R.id.tv_biaoti);
                viewHolder.tv_content = convertView.findViewById(R.id.tv_content);
                viewHolder.tv_content = convertView.findViewById(R.id.tv_content);
                viewHolder.tv_zan = convertView.findViewById(R.id.tv_zan);
                viewHolder.ll_pl = convertView.findViewById(R.id.ll_pl);
                viewHolder.tv_yuedui= convertView.findViewById(R.id.tv_yuedui);
                viewHolder.tv_gequ= convertView.findViewById(R.id.tv_gequ);
                viewHolder.ll_zan = convertView.findViewById(R.id.ll_zan);
                viewHolder.ll= convertView.findViewById(R.id.ll);
                convertView.setTag(viewHolder);
            } else {
                viewHolder = ( ViewHolder) convertView.getTag();
            }
            viewHolder.tv_name.setText(listdata.get(position).getUsername());
            viewHolder.tv_biaoti.setText("乐队名称："+listdata.get(position).getBiaoti());
            viewHolder.tv_content.setText("乐队成员："+listdata.get(position).getLeixing());
            viewHolder.tv_yuedui.setText("乐队简介："+listdata.get(position).getContent());
            viewHolder.tv_gequ.setText("乐队歌曲："+listdata.get(position).getTime());
            viewHolder.tv_zan.setText("点赞"+listdata.get(position).getZan());
            Glide.with(context).load(listdata.get(position).getPic()).into(viewHolder.iv_pic);
            if (!TextUtils.isEmpty(listdata.get(position).getHead_url())) {
                Glide.with(context).load(listdata.get(position).getHead_url()).into(viewHolder.image_head);
            }
            if (!TextUtils.isEmpty(listdata.get(position).getPic())) {
                viewHolder.iv_pic.setVisibility(View.VISIBLE);
                Glide.with(context).load(listdata.get(position).getPic()).into(viewHolder.iv_pic);
            }


            return convertView;
        }

        class ViewHolder {
            ImageView image_head;
            ImageView iv_pic;
            TextView tv_name, tv_biaoti,tv_yuedui,tv_gequ, tv_content, tv_zan;
            LinearLayout ll_pl, ll_zan,ll;
        }
    }
}